package com.itheima.hmshopping.dubbo.apiImpl;

import cn.hutool.core.collection.CollUtil;
import com.itheima.hmshopping.dubbo.api.PmsProductApi;
import com.itheima.hmshopping.dubbo.mapper.PmsProductMapper;
import com.itheima.hmshopping.entity.PmsProduct;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

@DubboService
public class PmsProductImpl implements PmsProductApi {
    @Autowired
    private PmsProductMapper pmsProductMapper;
    /**
     * 根据productIds获得所有的产品
     * @param productIds
     * @return
     */
    @Override
    public Map<Long, PmsProduct> getProductByIds(List<Long> productIds) {

        List<PmsProduct> pmsProducts = pmsProductMapper.selectBatchIds(productIds);
        Map<Long, PmsProduct> productMap = CollUtil.fieldValueMap(pmsProducts, "id");
        return productMap;
    }
}
